﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using VietImage.Models;
using VietImage.Logs;

namespace VietImage.Roles
{
    public class PartnerRole : RegisteredUserRole
    {
        #region Methods
        public List<ErrorItem> UploadImage(Image img, int id_Category, int isPrimary)
        {
            List<ErrorItem> errorList = Image.Insert(ref img, this.UserInfo.ID, id_Category, isPrimary, this.ID_Language);

            return errorList;
        }

        public List<ErrorItem> DeleteImage(int id)
        {
            List<ErrorItem> errorList = Image.Delete(id, this.UserInfo.ID, 0, ID_Language);

            return errorList;
        }

        public List<ErrorItem> EditImage(Image img, int isChangeSource)
        {
            List<ErrorItem> errorList = Image.ChangeInformation(img, this.UserInfo.ID, 0, this.ID_Language, isChangeSource);

            if (errorList == null)
                VietImageDB_Log.WriteLog(this.UserInfo.Username + " changed image information.");
            else
                VietImageDB_Log.WriteLog(this.UserInfo.Username + " cannot change image information." );

            return errorList;
        }

        public List<ErrorItem> EditDetailImage(DetailImage di)
        {
            List<ErrorItem> errorList = DetailImage.ChangeInformation(di, this.UserInfo.ID, ID_Language);

            return errorList;
        }

        public List<Image> ViewUploadedImagesDaily(int count, int from, out int n, DateTime date)
        {
            List<Image> l = Image.GetListAvailableByUploader(this.UserInfo.ID, count, from, out n, date);
            return l;
        }

        public List<Image> ViewUploadedImagesWeekly(int count, int from, out int n, DateTime beginDate, DateTime endDate)
        {
            List<Image> l = Image.GetListAvailableByUploader(this.UserInfo.ID, count, from, out n, beginDate, endDate);
            return l;
        }

        public List<Image> ViewUploadedImagesMonthly(int count, int from, out int n, int month, int year)
        {
            List<Image> l = Image.GetListAvailableByUploader(this.UserInfo.ID, count, from, out n, month, year);
            return l;
        }

        public List<Image> ViewNotPublishImages(int id_Category, int count, int from, out int n)
        {
            List<Image> l = Image.GetListNotPublish(this.UserInfo.ID, id_Category, count, from,  out n);
            return l;
        }

        public List<Category> ViewListAvailableSubCategories()
        {
            List<Category> lc = Category.GetListAvailableSubCategories(this.UserInfo.ID);
            return lc;
        }

        public List<ErrorItem> SetPrimaryImage(System.Data.Linq.Binary image, Category c)
        {
            List<ErrorItem> errorList = c.SetPrimaryImage(image, UserInfo.ID, ID_Language);

            return errorList;
        }

        public List<ErrorItem> InsertSubCategoryToCategory(Category c, int id_SubCategory)
        {
            List<ErrorItem> el = c.InsertSubCategory(this.UserInfo.ID, id_SubCategory, this.ID_Language);
            return el;
        }

        public List<ErrorItem> RemoveSubCategoryFromCategory(Category c, int id_SubCategory)
        {
            List<ErrorItem> el = c.RemoveSubCategory(this.UserInfo.ID, id_SubCategory, this.ID_Language);
            return el;
        }
        #endregion

        #region Reports
        public List<Image> GetListUploadedImages(DateTime date, int count, int from, out int n)
        {
            return Image.GetListUploadedImages(date, this.UserInfo.ID, count, from, out n);
        }

        public List<Image> GetListUploadedImages(int month, int year, int count, int from, out int n)
        {
            return Image.GetListUploadedImages(month, year, this.UserInfo.ID, count, from, out n);
        }

        public List<Image> GetListUploadedImages(DateTime beginDate, DateTime endDate, int count, int from, out int n)
        {
            return Image.GetListUploadedImages(beginDate, endDate, this.UserInfo.ID, count, from, out n);
        }
        #endregion
    }
}